package cn.itcast.service.impl;

import cn.itcast.mapper.ProductMapper;
import cn.itcast.pojo.Product;
import cn.itcast.service.ProductService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ProductServiceImpl implements ProductService {

    @Autowired
    private ProductMapper productMapper;

    @Override
    public Page<Product> findByPage(Integer page, Integer pageSize) {
        PageHelper.startPage(page, pageSize);
        Page<Product> products = productMapper.findByPage(page, pageSize);
        return products;
    }

    @Override
    public Product findById(Integer id) {
        Product product = productMapper.findById(id);
        return product;
    }

    @Override
    public boolean addProduct(Product product) {
        int row = productMapper.addProduct(product);
        return row > 0;
    }

    @Override
    public boolean updateProduct(Product product) {
        int row = productMapper.updateProduct(product);
        return row > 0;
    }
    @Override
    public boolean deleteById(Integer id) {
        int row = productMapper.deleteById(id);
        return row > 0;
    }
}
